home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / sprite / symmetry-dep.c.old < prev    next >
Encoding:
Text File  |  1990-11-15  |  32.0 KB  |  1,299 lines

  1. /* Low level interface to ptrace, for GDB when running under Unix.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* many 387-specific items of use taken from i386-dep.c */
  21.  
  22. #include "defs.h"
  23. #include "param.h"
  24. #include "frame.h"
  25. #include "inferior.h"
  26.  
  27. #include "sys/ptrace.h"
  28.  
  29. #include <stdio.h>
  30. #include <signal.h>
  31. #include <sys/param.h>
  32. #include <sys/dir.h>
  33. #include <sys/ioctl.h>
  34. #include <sys/stat.h>
  35. #include <a.out.h>
  36. #include <fcntl.h>
  37.  
  38. #include <sprite.h>
  39. #include <kernel/mach.h>
  40.  
  41. static long i386_get_frame_setup ();
  42. static long i386_follow_jump ();
  43.  
  44. #include <sgtty.h>
  45. #define TERMINAL struct sgttyb
  46.  
  47. extern int errno;
  48.  
  49. /* Nonzero if we are debugging an attached outside process
  50.    rather than an inferior.  */
  51.  
  52. static int attach_flag;
  53.  
  54. /* This function simply calls ptrace with the given arguments.  
  55.    It exists so that all calls to ptrace are isolated in this 
  56.    machine-dependent file. */
  57. int
  58. call_ptrace (request, pid, arg3, arg4)
  59.      int request, pid, arg3, arg4;
  60. {
  61.   return ptrace (request, pid, arg3, arg4);
  62. }
  63.  
  64.  
  65.  
  66. kill_inferior ()
  67. {
  68.   if (remote_debugging)
  69.     return;
  70.   if (inferior_pid == 0)
  71.     return;
  72.   ptrace (8, inferior_pid, 0, 0);
  73.   wait (0);
  74.   inferior_died ();
  75. }
  76.  
  77. /* This is used when GDB is exiting.  It gives less chance of error.*/
  78.  
  79. kill_inferior_fast ()
  80. {
  81.   if (remote_debugging)
  82.     return;
  83.   if (inferior_pid == 0)
  84.     return;
  85.   ptrace (8, inferior_pid, 0, 0);
  86.   wait (0);
  87. }
  88.  
  89. /* Resume execution of the inferior process.
  90.    If STEP is nonzero, single-step it.
  91.    If SIGNAL is nonzero, give it that signal.  */
  92.  
  93. void
  94. resume (step, signal)
  95.      int step;
  96.      int signal;
  97. {
  98.   errno = 0;
  99.   if (remote_debugging)
  100.     remote_resume (step, signal);
  101.   else
  102.     {
  103.       ptrace (step ? 9 : 7, inferior_pid, 1, signal);
  104.       if (errno)
  105.     perror_with_name ("ptrace");
  106.     }
  107. }
  108.  
  109. #ifdef ATTACH_DETACH
  110.  
  111. /* Start debugging the process whose number is PID.  */
  112.  
  113. attach (pid)
  114.      int pid;
  115. {
  116.   errno = 0;
  117.   ptrace (PTRACE_ATTACH, pid, 0, 0);
  118.   if (errno)
  119.     perror_with_name ("ptrace");
  120.   attach_flag = 1;
  121.   return pid;
  122. }
  123.  
  124. /* Stop debugging the process whose number is PID
  125.    and continue it with signal number SIGNAL.
  126.    SIGNAL = 0 means just continue it.  */
  127.  
  128. void
  129. detach (signal)
  130.      int signal;
  131. {
  132.   errno = 0;
  133.   ptrace (PTRACE_DETACH, inferior_pid, 1, signal);
  134.   if (errno)
  135.     perror_with_name ("ptrace");
  136.   attach_flag = 0;
  137. }
  138. #endif /* ATTACH_DETACH */
  139.  
  140.  
  141. store_inferior_registers(regno)
  142. int regno;
  143. {
  144.   Mach_RegState regs;
  145.   int reg_tmp, i;
  146.   extern char registers[];
  147.   
  148.   if (-1 == regno)
  149.     {
  150.       regs.userRegs.trapEAX = *(int *)®isters[REGISTER_BYTE(0)];
  151.       regs.userRegs.trapEBX = *(int *)®isters[REGISTER_BYTE(5)];
  152.       regs.userRegs.trapECX = *(int *)®isters[REGISTER_BYTE(2)];
  153.       regs.userRegs.trapEDX = *(int *)®isters[REGISTER_BYTE(1)];
  154.       regs.userRegs.trapESI = *(int *)®isters[REGISTER_BYTE(6)];
  155.       regs.userRegs.trapEDI = *(int *)®isters[REGISTER_BYTE(7)];
  156.       regs.userRegs.trapESP = *(Address *)®isters[REGISTER_BYTE(14)];
  157.       regs.userRegs.trapEBP = *(Address *)®isters[REGISTER_BYTE(15)];
  158.       regs.userRegs.trapEIP = *(Address *)®isters[REGISTER_BYTE(16)];
  159.       regs.userRegs.trapFlags = *(int *)®isters[REGISTER_BYTE(17)];
  160. #ifdef notdef
  161.      for (i = 0; i < 8; i++) {
  162.     regs.userFPURegs.fpa_regs[i] =
  163.       *(int *)®isters[REGISTER_BYTE(FP1_REGNUM+i)];
  164.       }
  165. #endif
  166.     }
  167.   else
  168.     {
  169.       reg_tmp = *(int *)®isters[REGISTER_BYTE(regno)];
  170.       ptrace(PTRACE_GETREGS, inferior_pid, ®s, 0);
  171.       switch (regno)
  172.     {
  173.     case 0:
  174.       regs.userRegs.trapEAX = *(int *)®isters[REGISTER_BYTE(0)];
  175.       break;
  176.     case 5:
  177.       regs.userRegs.trapEBX = *(int *)®isters[REGISTER_BYTE(5)];
  178.       break;
  179.     case 2:
  180.       regs.userRegs.trapECX = *(int *)®isters[REGISTER_BYTE(2)];
  181.       break;
  182.     case 1:
  183.       regs.userRegs.trapEDX = *(int *)®isters[REGISTER_BYTE(1)];
  184.       break;
  185.     case 6:
  186.       regs.userRegs.trapESI = *(int *)®isters[REGISTER_BYTE(6)];
  187.       break;
  188.     case 7:
  189.       regs.userRegs.trapEDI = *(int *)®isters[REGISTER_BYTE(7)];
  190.       break;
  191.     case 15:
  192.       regs.userRegs.trapEBP = *(Address *)®isters[REGISTER_BYTE(15)];
  193.       break;
  194.     case 14:
  195.       regs.userRegs.trapESP = *(Address *)®isters[REGISTER_BYTE(14)];
  196.       break;
  197.     case 16:
  198.       regs.userRegs.trapEIP = *(Address *)®isters[REGISTER_BYTE(16)];
  199.       break;
  200.     case 17:
  201.       regs.userRegs.trapFlags = *(int *)®isters[REGISTER_BYTE(17)];
  202.       break;
  203.     }
  204.     }
  205.   ptrace(PTRACE_SETREGS, inferior_pid, ®s, 0);
  206. }
  207.  
  208. void
  209. fetch_inferior_registers()
  210. {
  211.     int i;
  212.     Mach_RegState regs;
  213.     extern char registers[];
  214.  
  215.     ptrace(PTRACE_GETREGS, inferior_pid, ®s, 0);
  216.     *(int *)®isters[REGISTER_BYTE(0)] = regs.userRegs.trapEAX;
  217.     *(int *)®isters[REGISTER_BYTE(5)] = regs.userRegs.trapEBX;
  218.     *(int *)®isters[REGISTER_BYTE(2)] = regs.userRegs.trapECX;
  219.     *(int *)®isters[REGISTER_BYTE(1)] = regs.userRegs.trapEDX;
  220.     *(int *)®isters[REGISTER_BYTE(6)] = regs.userRegs.trapESI;
  221.     *(int *)®isters[REGISTER_BYTE(7)] = regs.userRegs.trapEDI;
  222.     *(Address *)®isters[REGISTER_BYTE(15)] = regs.userRegs.trapEBP;
  223.     *(Address *)®isters[REGISTER_BYTE(14)] = regs.userRegs.trapESP;
  224.     *(Address *)®isters[REGISTER_BYTE(16)] = regs.userRegs.trapEIP;
  225.     *(int *)®isters[REGISTER_BYTE(17)] = regs.userRegs.trapFlags;
  226.     bcopy(regs.userFPURegs.fpu_stack[0], ®isters[REGISTER_BYTE(3)], 10);
  227.     bcopy(regs.userFPURegs.fpu_stack[1], ®isters[REGISTER_BYTE(4)], 10);
  228.     bcopy(regs.userFPURegs.fpu_stack[2], ®isters[REGISTER_BYTE(8)], 10);
  229.     bcopy(regs.userFPURegs.fpu_stack[3], ®isters[REGISTER_BYTE(9)], 10);
  230.     bcopy(regs.userFPURegs.fpu_stack[4], ®isters[REGISTER_BYTE(10)], 10);
  231.     bcopy(regs.userFPURegs.fpu_stack[5], ®isters[REGISTER_BYTE(11)], 10);
  232.     bcopy(regs.userFPURegs.fpu_stack[6], ®isters[REGISTER_BYTE(12)], 10);
  233.     bcopy(regs.userFPURegs.fpu_stack[7], ®isters[REGISTER_BYTE(13)], 10);
  234. }
  235.  
  236.  
  237. /* Copy LEN bytes from inferior's memory starting at MEMADDR
  238.    to debugger memory starting at MYADDR.  */
  239.  
  240. read_inferior_memory (memaddr, myaddr, len)
  241.      CORE_ADDR memaddr;
  242.      char *myaddr;
  243.      int len;
  244. {
  245.   register int i;
  246.   /* Round starting address down to longword boundary.  */
  247.   register CORE_ADDR addr = memaddr & - sizeof (int);
  248.   /* Round ending address up; get number of longwords that makes.  */
  249.   register int count
  250.     = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
  251.   /* Allocate buffer of that many longwords.  */
  252.   register int *buffer = (int *) alloca (count * sizeof (int));
  253.  
  254.   /* Read all the longwords */
  255.   for (i = 0; i < count; i++, addr += sizeof (int)) {
  256.       errno = 0;
  257.       if (remote_debugging)
  258.       buffer[i] = remote_fetch_word (addr);
  259.       else
  260.       buffer[i] = ptrace (1, inferior_pid, addr, 0);
  261.       if (errno)
  262.       return errno;
  263.   }    
  264.  
  265.   /* Copy appropriate bytes out of the buffer.  */
  266.   bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
  267.   return 0;
  268. }
  269.  
  270. /* Copy LEN bytes of data from debugger memory at MYADDR
  271.    to inferior's memory at MEMADDR.
  272.    On failure (cannot write the inferior)
  273.    returns the value of errno.  */
  274.  
  275. int
  276. write_inferior_memory (memaddr, myaddr, len)
  277.      CORE_ADDR memaddr;
  278.      char *myaddr;
  279.      int len;
  280. {
  281.   register int i;
  282.   /* Round starting address down to longword boundary.  */
  283.   register CORE_ADDR addr = memaddr & - sizeof (int);
  284.   /* Round ending address up; get number of longwords that makes.  */
  285.   register int count
  286.     = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
  287.   /* Allocate buffer of that many longwords.  */
  288.   register int *buffer = (int *) alloca (count * sizeof (int));
  289.   extern int errno;
  290.  
  291.   /* Fill start and end extra bytes of buffer with existing memory data.  */
  292.  
  293.   if (remote_debugging)
  294.     buffer[0] = remote_fetch_word (addr);
  295.   else
  296.     buffer[0] = ptrace (1, inferior_pid, addr, 0);
  297.  
  298.   if (count > 1)
  299.     {
  300.       if (remote_debugging)
  301.     buffer[count - 1]
  302.       = remote_fetch_word (addr + (count - 1) * sizeof (int));
  303.       else
  304.     buffer[count - 1]
  305.       = ptrace (1, inferior_pid,
  306.             addr + (count - 1) * sizeof (int), 0);
  307.     }
  308.  
  309.   /* Copy data to be written over corresponding part of buffer */
  310.  
  311.   bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
  312.  
  313.   /* Write the entire buffer.  */
  314.  
  315.   for (i = 0; i < count; i++, addr += sizeof (int))
  316.     {
  317.       errno = 0;
  318.       if (remote_debugging)
  319.     remote_store_word (addr, buffer[i]);
  320.       else
  321.     ptrace (4, inferior_pid, addr, buffer[i]);
  322.       if (errno)
  323.     return errno;
  324.     }
  325.  
  326.   return 0;
  327. }
  328.  
  329.  
  330. /* Recognize COFF format systems because a.out.h defines AOUTHDR.  */
  331. #ifdef AOUTHDR
  332. #define COFF_FORMAT
  333. #endif
  334.  
  335.  
  336. #ifndef N_TXTADDR
  337. #define N_TXTADDR(hdr) 0
  338. #endif /* no N_TXTADDR */
  339.  
  340. #ifndef N_DATADDR
  341. #define N_DATADDR(hdr) hdr.a_text
  342. #endif /* no N_DATADDR */
  343.  
  344. /* Make COFF and non-COFF names for things a little more compatible
  345.    to reduce conditionals later.  */
  346.  
  347. #ifdef COFF_FORMAT
  348. #define a_magic magic
  349. #endif
  350.  
  351. #ifndef COFF_FORMAT
  352. #define AOUTHDR struct exec
  353. #endif
  354.  
  355. extern char *sys_siglist[];
  356.  
  357. /* Hook for `exec_file_command' command to call.  */
  358.  
  359. void (*exec_file_display_hook) ();
  360.    
  361. /* File names of core file and executable file.  */
  362.  
  363. extern char *corefile;
  364. extern char *execfile;
  365.  
  366. /* Descriptors on which core file and executable file are open.
  367.    Note that the execchan is closed when an inferior is created
  368.    and reopened if the inferior dies or is killed.  */
  369.  
  370. extern int corechan;
  371. extern int execchan;
  372.  
  373. /* Last modification time of executable file.
  374.    Also used in source.c to compare against mtime of a source file.  */
  375.  
  376. int exec_mtime;
  377.  
  378. /* Virtual addresses of bounds of the two areas of memory in the core file.  */
  379.  
  380. extern CORE_ADDR data_start;
  381. extern CORE_ADDR data_end;
  382. extern CORE_ADDR stack_start;
  383. extern CORE_ADDR stack_end;
  384.  
  385. /* Virtual addresses of bounds of two areas of memory in the exec file.
  386.    Note that the data area in the exec file is used only when there is no core file.  */
  387.  
  388. extern CORE_ADDR text_start;
  389. extern CORE_ADDR text_end;
  390.  
  391. extern CORE_ADDR exec_data_start;
  392. extern CORE_ADDR exec_data_end;
  393.  
  394. /* Address in executable file of start of text area data.  */
  395.  
  396. extern int text_offset;
  397.  
  398. /* Address in executable file of start of data area data.  */
  399.  
  400. extern int exec_data_offset;
  401.  
  402. /* Address in core file of start of data area data.  */
  403.  
  404. extern int data_offset;
  405.  
  406. /* Address in core file of start of stack area data.  */
  407.  
  408. extern int stack_offset;
  409.   
  410. #ifdef COFF_FORMAT
  411. /* various coff data structures */
  412.  
  413. extern FILHDR file_hdr;
  414. extern SCNHDR text_hdr;
  415. extern SCNHDR data_hdr;
  416.  
  417. #endif /* not COFF_FORMAT */
  418.  
  419. /* a.out header saved in core file.  */
  420.   
  421. extern AOUTHDR core_aouthdr;
  422.  
  423. /* a.out header of exec file.  */
  424.  
  425. extern AOUTHDR exec_aouthdr;
  426.  
  427. extern void validate_files ();
  428. unsigned int register_addr ();
  429.  
  430. core_file_command (filename, from_tty)
  431.      char *filename;
  432.      int from_tty;
  433. {
  434.   error("No cores in Sprite\n");
  435.   return;
  436. #ifdef notdef
  437.   int val;
  438.   extern char registers[];
  439.  
  440.   /* Discard all vestiges of any previous core file
  441.      and mark data and stack spaces as empty.  */
  442.  
  443.   if (corefile)
  444.     free (corefile);
  445.   corefile = 0;
  446.  
  447.   if (corechan >= 0)
  448.     close (corechan);
  449.   corechan = -1;
  450.  
  451.   data_start = 0;
  452.   data_end = 0;
  453.   stack_start = STACK_END_ADDR;
  454.   stack_end = STACK_END_ADDR;
  455.  
  456.   /* Now, if a new core file was specified, open it and digest it.  */
  457.  
  458.   if (filename)
  459.     {
  460.       filename = tilde_expand (filename);
  461.       make_cleanup (free, filename);
  462.       
  463.       if (have_inferior_p ())
  464.     error ("To look at a core file, you must kill the inferior with \"kill\".");
  465.       corechan = open (filename, O_RDONLY, 0);
  466.       if (corechan < 0)
  467.     perror_with_name (filename);
  468.       /* 4.2-style (and perhaps also sysV-style) core dump file.  */
  469.       {
  470.     struct user u;
  471.     int reg_offset;
  472.  
  473.     val = myread (corechan, &u, sizeof u);
  474.     if (val < 0)
  475.       perror_with_name (filename);
  476.     data_start = exec_data_start;
  477.  
  478.     data_end = data_start + NBPG * (u.u_dsize - u.u_tsize);
  479.     stack_start = stack_end - NBPG * u.u_ssize;
  480.     data_offset = NBPG * UPAGES;
  481.     stack_offset = ctob(UPAGES + u.u_dsize - u.u_tsize);
  482.     reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR;
  483. printf("u.u_tsize= %#x, u.u_dsize= %#x, u.u_ssize= %#x, stack_off= %#x\n",
  484.        u.u_tsize, u.u_dsize, u.u_ssize, stack_offset);
  485.  
  486.     core_aouthdr.a_magic = 0;
  487.  
  488.     /* Read the register values out of the core file and store
  489.        them where `read_register' will find them.  */
  490.  
  491.     {
  492.       register int regno;
  493.  
  494.       for (regno = 0; regno < NUM_REGS; regno++)
  495.         {
  496.           char buf[MAX_REGISTER_RAW_SIZE];
  497.  
  498.           val = lseek (corechan, register_addr (regno, reg_offset), 0);
  499.           if (val < 0)
  500.         perror_with_name (filename);
  501.  
  502.            val = myread (corechan, buf, sizeof buf);
  503.           if (val < 0)
  504.         perror_with_name (filename);
  505.           supply_register (regno, buf);
  506.         }
  507.     }
  508.       }
  509.       if (filename[0] == '/')
  510.     corefile = savestring (filename, strlen (filename));
  511.       else
  512.     {
  513.       corefile = concat (current_directory, "/", filename);
  514.     }
  515.  
  516.       set_current_frame(create_new_frame(read_register(FP_REGNUM),
  517.                      read_pc()));
  518. /*      set_current_frame (read_register (FP_REGNUM));*/
  519.       select_frame (get_current_frame (), 0);
  520.       validate_files ();
  521.     }
  522.   else if (from_tty)
  523.     printf ("No core file now.\n");
  524. #endif /* notdef */
  525. }
  526.  
  527. exec_file_command (filename, from_tty)
  528.      char *filename;
  529.      int from_tty;
  530. {
  531.   int val;
  532.  
  533.   /* Eliminate all traces of old exec file.
  534.      Mark text segment as empty.  */
  535.  
  536.   if (execfile)
  537.     free (execfile);
  538.   execfile = 0;
  539.   data_start = 0;
  540.   data_end -= exec_data_start;
  541.   text_start = 0;
  542.   text_end = 0;
  543.   exec_data_start = 0;
  544.   exec_data_end = 0;
  545.   if (execchan >= 0)
  546.     close (execchan);
  547.   execchan = -1;
  548.  
  549.   /* Now open and digest the file the user requested, if any.  */
  550.  
  551.   if (filename)
  552.     {
  553.       filename = tilde_expand (filename);
  554.       make_cleanup (free, filename);
  555.  
  556.       execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
  557.             &execfile);
  558.       if (execchan < 0)
  559.     perror_with_name (filename);
  560.  
  561. #ifdef COFF_FORMAT
  562.       {
  563.     int aout_hdrsize;
  564.     int num_sections;
  565.  
  566.     if (read_file_hdr (execchan, &file_hdr) < 0)
  567.       error ("\"%s\": not in executable format.", execfile);
  568.  
  569.     aout_hdrsize = file_hdr.f_opthdr;
  570.     num_sections = file_hdr.f_nscns;
  571.  
  572.     if (read_aout_hdr (execchan, &exec_aouthdr, aout_hdrsize) < 0)
  573.       error ("\"%s\": can't read optional aouthdr", execfile);
  574.  
  575.     if (read_section_hdr (execchan, _TEXT, &text_hdr, num_sections,
  576.                           aout_hdrsize) < 0)
  577.       error ("\"%s\": can't read text section header", execfile);
  578.  
  579.     if (read_section_hdr (execchan, _DATA, &data_hdr, num_sections,
  580.                           aout_hdrsize) < 0)
  581.       error ("\"%s\": can't read data section header", execfile);
  582.  
  583.     text_start = exec_aouthdr.text_start;
  584.     text_end = text_start + exec_aouthdr.tsize;
  585.     text_offset = text_hdr.s_scnptr;
  586.     exec_data_start = exec_aouthdr.data_start;
  587.     exec_data_end = exec_data_start + exec_aouthdr.dsize;
  588.     exec_data_offset = data_hdr.s_scnptr;
  589.     data_start = exec_data_start;
  590.     data_end += exec_data_start;
  591.     exec_mtime = file_hdr.f_timdat;
  592.       }
  593. #else /* not COFF_FORMAT */
  594.       {
  595.     struct stat st_exec;
  596.  
  597.     val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR));
  598.  
  599.     if (val < 0)
  600.       perror_with_name (filename);
  601.  
  602.     text_start = N_ADDRADJ(exec_aouthdr);
  603.         exec_data_start = round(exec_aouthdr.a_text, NBPG);
  604.     text_offset = N_TXTOFF (exec_aouthdr);
  605.     exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text;
  606.     text_end = exec_aouthdr.a_text;
  607.         exec_data_end = exec_data_start + exec_aouthdr.a_data;
  608.     data_start = exec_data_start;
  609.     data_end = data_start + exec_aouthdr.a_data;
  610.     exec_data_offset = N_TXTOFF(exec_aouthdr);
  611.     fstat (execchan, &st_exec);
  612.     exec_mtime = st_exec.st_mtime;
  613.       }
  614. #endif /* not COFF_FORMAT */
  615.  
  616.       validate_files ();
  617.     }
  618.   else if (from_tty)
  619.     printf ("No exec file now.\n");
  620.  
  621.   /* Tell display code (if any) about the changed file name.  */
  622.   if (exec_file_display_hook)
  623.     (*exec_file_display_hook) (filename);
  624. }
  625.  
  626. /* rounds 'one' up to divide evenly by 'two' */
  627.  
  628. int
  629. round(one,two)
  630. register int one, two;
  631.  
  632. {
  633.     register int temp;
  634.     temp = (one/two)*two;
  635.     if (one != temp) {
  636.     temp += two;
  637.     }
  638.     return temp;
  639. }
  640.  
  641.  
  642. static CORE_ADDR codestream_next_addr;
  643. static CORE_ADDR codestream_addr;
  644. static unsigned char codestream_buf[sizeof (int)];
  645. static int codestream_off;
  646. static int codestream_cnt;
  647.  
  648. #define codestream_tell() (codestream_addr + codestream_off)
  649. #define codestream_peek() (codestream_cnt == 0 ? \
  650.                codestream_fill(1): codestream_buf[codestream_off])
  651. #define codestream_get() (codestream_cnt-- == 0 ? \
  652.              codestream_fill(0) : codestream_buf[codestream_off++])
  653.  
  654.  
  655. static unsigned char 
  656. codestream_fill (peek_flag)
  657. {
  658.   codestream_addr = codestream_next_addr;
  659.   codestream_next_addr += sizeof (int);
  660.   codestream_off = 0;
  661.   codestream_cnt = sizeof (int);
  662.   read_memory (codestream_addr,
  663.            (unsigned char *)codestream_buf,
  664.            sizeof (int));
  665.   
  666.   if (peek_flag)
  667.     return (codestream_peek());
  668.   else
  669.     return (codestream_get());
  670. }
  671.  
  672. static void
  673. codestream_seek (place)
  674. {
  675.   codestream_next_addr = place & -sizeof (int);
  676.   codestream_cnt = 0;
  677.   codestream_fill (1);
  678.   while (codestream_tell() != place)
  679.     codestream_get ();
  680. }
  681.  
  682. static void
  683. codestream_read (buf, count)
  684.      unsigned char *buf;
  685. {
  686.   unsigned char *p;
  687.   int i;
  688.   p = buf;
  689.   for (i = 0; i < count; i++)
  690.     *p++ = codestream_get ();
  691. }
  692.  
  693. /* from i386-dep.c */
  694. i386_frame_find_saved_regs (fip, fsrp)
  695.      struct frame_info *fip;
  696.      struct frame_saved_regs *fsrp;
  697. {
  698.   unsigned long locals;
  699.   unsigned char *p;
  700.   unsigned char op;
  701.   CORE_ADDR dummy_bottom;
  702.   CORE_ADDR adr;
  703.   int i;
  704.   
  705.   bzero (fsrp, sizeof *fsrp);
  706.   
  707.   /* if frame is the end of a dummy, compute where the
  708.    * beginning would be
  709.    */
  710.   dummy_bottom = fip->frame - 4 - NUM_REGS*4 - CALL_DUMMY_LENGTH;
  711.   
  712.   /* check if the PC is in the stack, in a dummy frame */
  713.   if (dummy_bottom <= fip->pc && fip->pc <= fip->frame) 
  714.     {
  715.       /* all regs were saved by push_call_dummy () */
  716.       adr = fip->frame - 4;
  717.       for (i = 0; i < NUM_REGS; i++) 
  718.     {
  719.       fsrp->regs[i] = adr;
  720.       adr -= 4;
  721.     }
  722.       return;
  723.     }
  724.   
  725.   locals = i386_get_frame_setup (get_pc_function_start (fip->pc));
  726.   
  727.   if (locals >= 0) 
  728.     {
  729.       adr = fip->frame - 4 - locals;
  730.       for (i = 0; i < 8; i++) 
  731.     {
  732.       op = codestream_get ();
  733.       if (op < 0x50 || op > 0x57)
  734.         break;
  735.       fsrp->regs[op - 0x50] = adr;
  736.       adr -= 4;
  737.     }
  738.     }
  739.   
  740.   fsrp->regs[PC_REGNUM] = fip->frame + 4;
  741.   fsrp->regs[FP_REGNUM] = fip->frame;
  742. }
  743.  
  744. /* from i386-dep.c */
  745. static
  746. print_387_control_word (control)
  747. unsigned short control;
  748. {
  749.   printf ("control 0x%04x: ", control);
  750.   printf ("compute to ");
  751.   switch ((control >> 8) & 3) 
  752.     {
  753.     case 0: printf ("24 bits; "); break;
  754.     case 1: printf ("(bad); "); break;
  755.     case 2: printf ("53 bits; "); break;
  756.     case 3: printf ("64 bits; "); break;
  757.     }
  758.   printf ("round ");
  759.   switch ((control >> 10) & 3) 
  760.     {
  761.     case 0: printf ("NEAREST; "); break;
  762.     case 1: printf ("DOWN; "); break;
  763.     case 2: printf ("UP; "); break;
  764.     case 3: printf ("CHOP; "); break;
  765.     }
  766.   if (control & 0x3f) 
  767.     {
  768.       printf ("mask:");
  769.       if (control & 0x0001) printf (" INVALID");
  770.       if (control & 0x0002) printf (" DENORM");
  771.       if (control & 0x0004) printf (" DIVZ");
  772.       if (control & 0x0008) printf (" OVERF");
  773.       if (control & 0x0010) printf (" UNDERF");
  774.       if (control & 0x0020) printf (" LOS");
  775.       printf (";");
  776.     }
  777.   printf ("\n");
  778.   if (control & 0xe080) printf ("warning: reserved bits on 0x%x\n",
  779.                 control & 0xe080);
  780. }
  781.  
  782. static
  783. print_387_status_word (status)
  784.      unsigned short status;
  785. {
  786.   printf ("status %#04x: ", status);
  787.   if (status & 0xff) {
  788.       printf ("exceptions:");    /* exception names match <machine/fpu.h> */
  789.       if (status & 0x0001) printf (" FLTINV");
  790.       if (status & 0x0002) printf (" FLTDEN");
  791.       if (status & 0x0004) printf (" FLTDIV");
  792.       if (status & 0x0008) printf (" FLTOVF");
  793.       if (status & 0x0010) printf (" FLTUND");
  794.       if (status & 0x0020) printf (" FLTPRE");
  795.       if (status & 0x0040) printf (" FLTSTK");
  796.       printf ("; ");
  797.     }
  798.   printf ("flags: %d%d%d%d; ",
  799.       (status & 0x4000) != 0,
  800.       (status & 0x0400) != 0,
  801.       (status & 0x0200) != 0,
  802.       (status & 0x0100) != 0);
  803.   
  804.   printf ("top %d\n", (status >> 11) & 7);
  805. }
  806.  
  807. static
  808. print_fpu_status(ep)
  809. Mach_RegState ep;
  810.  
  811. {
  812.     error("Unimplemented.\n");
  813. #ifdef notdef
  814.     int i;
  815.     int bothstatus;
  816.     int top;
  817.     int fpreg;
  818.     unsigned char *p;
  819.     
  820.     printf("80387:");
  821.     if (ep.pr_fpu.fpu_ip == 0) {
  822.     printf(" not in use.\n");
  823.     return;
  824.     } else {
  825.     printf("\n");
  826.     }
  827.     if (ep.pr_fpu.fpu_status != 0) {
  828.     print_387_status_word (ep.pr_fpu.fpu_status);
  829.     }
  830.     print_387_control_word (ep.pr_fpu.fpu_control);
  831.     printf ("last exception: ");
  832.     printf ("opcode 0x%x; ", ep.pr_fpu.fpu_rsvd4);
  833.     printf ("pc 0x%x:0x%x; ", ep.pr_fpu.fpu_cs, ep.pr_fpu.fpu_ip);
  834.     printf ("operand 0x%x:0x%x\n", ep.pr_fpu.fpu_data_offset, ep.pr_fpu.fpu_op_sel);
  835.     
  836.     top = (ep.pr_fpu.fpu_status >> 11) & 7;
  837.     
  838.     printf ("regno  tag  msb              lsb  value\n");
  839.     for (fpreg = 7; fpreg >= 0; fpreg--) 
  840.     {
  841.         double val;
  842.         
  843.         printf ("%s %d: ", fpreg == top ? "=>" : "  ", fpreg);
  844.         
  845.         switch ((ep.pr_fpu.fpu_tag >> (fpreg * 2)) & 3) 
  846.         {
  847.         case 0: printf ("valid "); break;
  848.         case 1: printf ("zero  "); break;
  849.         case 2: printf ("trap  "); break;
  850.         case 3: printf ("empty "); break;
  851.         }
  852.         for (i = 9; i >= 0; i--)
  853.         printf ("%02x", ep.pr_fpu.fpu_stack[fpreg][i]);
  854.         
  855.         i387_to_double (ep.pr_fpu.fpu_stack[fpreg], (char *)&val);
  856.         printf ("  %g\n", val);
  857.     }
  858.     if (ep.pr_fpu.fpu_rsvd1)
  859.     printf ("warning: rsvd1 is 0x%x\n", ep.pr_fpu.fpu_rsvd1);
  860.     if (ep.pr_fpu.fpu_rsvd2)
  861.     printf ("warning: rsvd2 is 0x%x\n", ep.pr_fpu.fpu_rsvd2);
  862.     if (ep.pr_fpu.fpu_rsvd3)
  863.     printf ("warning: rsvd3 is 0x%x\n", ep.pr_fpu.fpu_rsvd3);
  864.     if (ep.pr_fpu.fpu_rsvd5)
  865.     printf ("warning: rsvd5 is 0x%x\n", ep.pr_fpu.fpu_rsvd5);
  866. #endif /* notdef */
  867. }
  868.  
  869.  
  870. print_1167_control_word(pcr)
  871. unsigned int pcr;
  872.  
  873. {
  874.     error("Unimplemented.\n");
  875. #ifdef notdef
  876.     int pcr_tmp;
  877.  
  878.     pcr_tmp = pcr & FPA_PCR_MODE;
  879.     printf("\tMODE= %#x; RND= %#x ", pcr_tmp, pcr_tmp & 12);
  880.     switch (pcr_tmp & 12) {
  881.     case 0:
  882.     printf("RN (Nearest Value)");
  883.     break;
  884.     case 1:
  885.     printf("RZ (Zero)");
  886.     break;
  887.     case 2:
  888.     printf("RP (Positive Infinity)");
  889.     break;
  890.     case 3:
  891.     printf("RM (Negative Infinity)");
  892.     break;
  893.     }
  894.     printf("; IRND= %d ", pcr_tmp & 2);
  895.     if (0 == pcr_tmp & 2) {
  896.     printf("(same as RND)\n");
  897.     } else {
  898.     printf("(toward zero)\n");
  899.     }
  900.     pcr_tmp = pcr & FPA_PCR_EM;
  901.     printf("\tEM= %#x", pcr_tmp);
  902.     if (pcr_tmp & FPA_PCR_EM_DM) printf(" DM");
  903.     if (pcr_tmp & FPA_PCR_EM_UOM) printf(" UOM");
  904.     if (pcr_tmp & FPA_PCR_EM_PM) printf(" PM");
  905.     if (pcr_tmp & FPA_PCR_EM_UM) printf(" UM");
  906.     if (pcr_tmp & FPA_PCR_EM_OM) printf(" OM");
  907.     if (pcr_tmp & FPA_PCR_EM_ZM) printf(" ZM");
  908.     if (pcr_tmp & FPA_PCR_EM_IM) printf(" IM");
  909.     printf("\n");
  910.     pcr_tmp = FPA_PCR_CC;
  911.     printf("\tCC= %#x", pcr_tmp);
  912.     if (pcr_tmp & FPA_PCR_20MHZ) printf(" 20MHZ");
  913.     if (pcr_tmp & FPA_PCR_CC_Z) printf(" Z");
  914.     if (pcr_tmp & FPA_PCR_CC_C2) printf(" C2");
  915.     if (pcr_tmp & FPA_PCR_CC_C1) printf(" C1");
  916.     switch (pcr_tmp) {
  917.     case FPA_PCR_CC_Z:
  918.     printf(" (Equal)");
  919.     break;
  920.     case FPA_PCR_CC_C1:
  921.     printf(" (Less than)");
  922.     break;
  923.     case 0:
  924.     printf(" (Greater than)");
  925.     break;
  926.     case FPA_PCR_CC_Z | FPA_PCR_CC_C1 | FPA_PCR_CC_C2:
  927.     printf(" (Unordered)");
  928.     break;
  929.     default:
  930.     printf(" (Undefined)");
  931.     break;
  932.     }
  933.     printf("\n");
  934.     pcr_tmp = pcr & FPA_PCR_AE;
  935.     printf("\tAE= %#x", pcr_tmp);
  936.     if (pcr_tmp & FPA_PCR_AE_DE) printf(" DE");
  937.     if (pcr_tmp & FPA_PCR_AE_UOE) printf(" UOE");
  938.     if (pcr_tmp & FPA_PCR_AE_PE) printf(" PE");
  939.     if (pcr_tmp & FPA_PCR_AE_UE) printf(" UE");
  940.     if (pcr_tmp & FPA_PCR_AE_OE) printf(" OE");
  941.     if (pcr_tmp & FPA_PCR_AE_ZE) printf(" ZE");
  942.     if (pcr_tmp & FPA_PCR_AE_EE) printf(" EE");
  943.     if (pcr_tmp & FPA_PCR_AE_IE) printf(" IE");
  944.     printf("\n");
  945. #endif /* notdef */
  946. }
  947.  
  948. print_1167_regs(regs)
  949. long regs[FPA_NREGS];
  950.  
  951. {
  952.     error("Unimplemented.\n");
  953. #ifdef notdef
  954.     int i;
  955.  
  956.     union {
  957.     double    d;
  958.     long    l[2];
  959.     } xd;
  960.     union {
  961.     float    f;
  962.     long    l;
  963.     } xf;
  964.  
  965.  
  966.     for (i = 0; i < FPA_NREGS; i++) {
  967.     xf.l = regs[i];
  968.     printf("%%fp%d: raw= %#x, single= %f", i+1, regs[i], xf.f);
  969.     if (!(i & 1)) {
  970.         printf("\n");
  971.     } else {
  972.         xd.l[1] = regs[i];
  973.         xd.l[0] = regs[i+1];
  974.         printf(", double= %f\n", xd.d);
  975.     }
  976.     }
  977. #endif /* notdef */
  978. }
  979.  
  980. print_fpa_status(ep)
  981. Mach_RegState ep;
  982.  
  983. {
  984.     error("Unimplemented.\n");
  985. #ifdef notdef
  986.     printf("WTL 1167:");
  987.     if (ep.pr_fpa.fpa_pcr !=0) {
  988.     printf("\n");
  989.     print_1167_control_word(ep.pr_fpa.fpa_pcr);
  990.     print_1167_regs(ep.pr_fpa.fpa_regs);
  991.     } else {
  992.     printf(" not in use.\n");
  993.     }
  994. #endif /* notdef */
  995. }
  996.  
  997. i386_float_info ()
  998.  
  999. {
  1000.     error("Unimplemented.\n");
  1001. #ifdef notdef
  1002.     char ubuf[UPAGES*NBPG];
  1003.     struct pt_regset regset;
  1004.     extern int corechan;
  1005.     
  1006.     if (have_inferior_p()) {
  1007.     call_ptrace(PTRACE_GETREGS, inferior_pid, ®set, 0);
  1008.     } else {
  1009.     if (lseek (corechan, 0, 0) < 0) {
  1010.         perror ("seek on core file");
  1011.     }
  1012.     if (myread (corechan, ubuf, UPAGES*NBPG) < 0) {
  1013.         perror ("read on core file");
  1014.     }
  1015.     /* only interested in the floating point registers */
  1016.     regset.pr_fpu = ((struct user *) ubuf)->u_fpusave;
  1017.     regset.pr_fpa = ((struct user *) ubuf)->u_fpasave;
  1018.     }
  1019.     print_fpu_status(regset);
  1020.     print_fpa_status(regset);
  1021. #endif /* notdef */
  1022. }
  1023.  
  1024. i387_to_double (from, to)
  1025.      char *from;
  1026.      char *to;
  1027. {
  1028.     *(double *)to = -1.11;
  1029. #ifdef notdef
  1030.   long *lp;
  1031.   /* push extended mode on 387 stack, then pop in double mode
  1032.    *
  1033.    * first, set exception masks so no error is generated -
  1034.    * number will be rounded to inf or 0, if necessary 
  1035.    */
  1036.   asm ("pushl %eax");         /* grab a stack slot */
  1037.   asm ("fstcw (%esp)");        /* get 387 control word */
  1038.   asm ("movl (%esp),%eax");    /* save old value */
  1039.   asm ("orl $0x3f,%eax");        /* mask all exceptions */
  1040.   asm ("pushl %eax");
  1041.   asm ("fldcw (%esp)");        /* load new value into 387 */
  1042.   
  1043.   asm ("movl 8(%ebp),%eax");
  1044.   asm ("fldt (%eax)");        /* push extended number on 387 stack */
  1045.   asm ("fwait");
  1046.   asm ("movl 12(%ebp),%eax");
  1047.   asm ("fstpl (%eax)");        /* pop double */
  1048.   asm ("fwait");
  1049.   
  1050.   asm ("popl %eax");        /* flush modified control word */
  1051.   asm ("fnclex");            /* clear exceptions */
  1052.   asm ("fldcw (%esp)");        /* restore original control word */
  1053.   asm ("popl %eax");        /* flush saved copy */
  1054. #endif
  1055. }
  1056.  
  1057. double_to_i387 (from, to)
  1058.      char *from;
  1059.      char *to;
  1060. {
  1061.   /* push double mode on 387 stack, then pop in extended mode
  1062.    * no errors are possible because every 64-bit pattern
  1063.    * can be converted to an extended
  1064.    */
  1065.   asm ("movl 8(%ebp),%eax");
  1066.   asm ("fldl (%eax)");
  1067.   asm ("fwait");
  1068.   asm ("movl 12(%ebp),%eax");
  1069.   asm ("fstpt (%eax)");
  1070.   asm ("fwait");
  1071. }
  1072.  
  1073. static long
  1074. i386_get_frame_setup (pc)
  1075. {
  1076.   unsigned char op;
  1077.   
  1078.   codestream_seek (pc);
  1079.   
  1080.   i386_follow_jump ();
  1081.   
  1082.   op = codestream_get ();
  1083.   
  1084.   if (op == 0x58) /* popl %eax */
  1085.     {
  1086.       /*
  1087.        * this function must start with
  1088.        * 
  1089.        *    popl %eax          0x58
  1090.        *    xchgl %eax, (%esp)  0x87 0x04 0x24
  1091.        * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
  1092.        *
  1093.        * (the system 5 compiler puts out the second xchg
  1094.        * inst, and the assembler doesn't try to optimize it,
  1095.        * so the 'sib' form gets generated)
  1096.        * 
  1097.        * this sequence is used to get the address of the return
  1098.        * buffer for a function that returns a structure
  1099.        */
  1100.       int pos;
  1101.       unsigned char buf[4];
  1102.       static unsigned char proto1[3] = { 0x87,0x04,0x24 };
  1103.       static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
  1104.       pos = codestream_tell ();
  1105.       codestream_read (buf, 4);
  1106.       if (bcmp (buf, proto1, 3) == 0)
  1107.     pos += 3;
  1108.       else if (bcmp (buf, proto2, 4) == 0)
  1109.     pos += 4;
  1110.       
  1111.       codestream_seek (pos);
  1112.       op = codestream_get (); /* update next opcode */
  1113.     }
  1114.   
  1115.   if (op == 0x55)             /* pushl %esp */
  1116.     {
  1117.       if (codestream_get () != 0x8b)    /* movl %esp, %ebp (2bytes) */
  1118.     return (-1);
  1119.       if (codestream_get () != 0xec)
  1120.     return (-1);
  1121.       /*
  1122.        * check for stack adjustment 
  1123.        *
  1124.        *  subl $XXX, %esp
  1125.        *
  1126.        * note: you can't subtract a 16 bit immediate
  1127.        * from a 32 bit reg, so we don't have to worry
  1128.        * about a data16 prefix 
  1129.        */
  1130.       op = codestream_peek ();
  1131.       if (op == 0x83)  /* subl with 8 bit immed */
  1132.     {
  1133.       codestream_get ();
  1134.       if (codestream_get () != 0xec)
  1135.         return (-1);
  1136.       /* subl with signed byte immediate 
  1137.        * (though it wouldn't make sense to be negative)
  1138.        */
  1139.       return (codestream_get());
  1140.     }
  1141.       else if (op == 0x81)  /* subl with 32 bit immed */
  1142.     {
  1143.       int locals;
  1144.       if (codestream_get () != 0xec)
  1145.         return (-1);
  1146.       /* subl with 32 bit immediate */
  1147.       codestream_read ((unsigned char *)&locals, 4);
  1148.       return (locals);
  1149.     } 
  1150.       else 
  1151.     {
  1152.       return (0);
  1153.     }
  1154.     } 
  1155.   else if (op == 0xc8) 
  1156.     {
  1157.       /* enter instruction: arg is 16 unsigned immed */
  1158.       unsigned short slocals;
  1159.       codestream_read ((unsigned char *)&slocals, 2);
  1160.       codestream_get (); /* flush final byte of enter instruction */
  1161.       return (slocals);
  1162.     }
  1163.   return (-1);
  1164. }
  1165.  
  1166.  
  1167. /* Return number of args passed to a frame.
  1168.    Can return -1, meaning no way to tell.  */
  1169.  
  1170. /* on the 386, the instruction following the call could be:
  1171.  *  popl %ecx        -  one arg
  1172.  *  addl $imm, %esp  -  imm/4 args; imm may be 8 or 32 bits
  1173.  *  anything else    -  zero args
  1174.  */
  1175.  
  1176. int
  1177. i386_frame_num_args (fi)
  1178.      struct frame_info fi;
  1179. {
  1180.   int retpc;                        
  1181.   unsigned char op;                    
  1182.   struct frame_info *pfi;
  1183.  
  1184.   pfi = get_prev_frame_info ((fi));            
  1185.   if (pfi == 0)
  1186.     {
  1187.       /* Note:  this can happen if we are looking at the frame for
  1188.      main, because FRAME_CHAIN_VALID won't let us go into
  1189.      start.  If we have debugging symbols, that's not really
  1190.      a big deal; it just means it will only show as many arguments
  1191.      to main as are declared.  */
  1192.       return -1;
  1193.     }
  1194.   else
  1195.     {
  1196.       retpc = pfi->pc;                    
  1197.       op = read_memory_integer (retpc, 1);            
  1198.       if (op == 0x59)                    
  1199.     /* pop %ecx */                   
  1200.     return 1;                
  1201.       else if (op == 0x83)
  1202.     {
  1203.       op = read_memory_integer (retpc+1, 1);    
  1204.       if (op == 0xc4)                
  1205.         /* addl $<signed imm 8 bits>, %esp */    
  1206.         return (read_memory_integer (retpc+2,1)&0xff)/4;
  1207.       else
  1208.         return 0;
  1209.     }
  1210.       else if (op == 0x81)
  1211.     { /* add with 32 bit immediate */
  1212.       op = read_memory_integer (retpc+1, 1);    
  1213.       if (op == 0xc4)                
  1214.         /* addl $<imm 32>, %esp */        
  1215.         return read_memory_integer (retpc+2, 4) / 4;
  1216.       else
  1217.         return 0;
  1218.     }
  1219.       else
  1220.     {
  1221.       return 0;
  1222.     }
  1223.     }
  1224. }
  1225.  
  1226. /* next instruction is a jump, move to target */
  1227. static long
  1228. i386_follow_jump ()
  1229. {
  1230.   int long_delta;
  1231.   short short_delta;
  1232.   char byte_delta;
  1233.   int data16;
  1234.   int pos;
  1235.   
  1236.   pos = codestream_tell ();
  1237.   
  1238.   data16 = 0;
  1239.   if (codestream_peek () == 0x66)
  1240.     {
  1241.       codestream_get ();
  1242.       data16 = 1;
  1243.     }
  1244.   
  1245.   switch (codestream_get ())
  1246.     {
  1247.     case 0xe9:
  1248.       /* relative jump: if data16 == 0, disp32, else disp16 */
  1249.       if (data16)
  1250.     {
  1251.       codestream_read ((unsigned char *)&short_delta, 2);
  1252.       pos += short_delta + 3; /* include size of jmp inst */
  1253.     }
  1254.       else
  1255.     {
  1256.       codestream_read ((unsigned char *)&long_delta, 4);
  1257.       pos += long_delta + 5;
  1258.     }
  1259.       break;
  1260.     case 0xeb:
  1261.       /* relative jump, disp8 (ignore data16) */
  1262.       codestream_read ((unsigned char *)&byte_delta, 1);
  1263.       pos += byte_delta + 2;
  1264.       break;
  1265.     }
  1266.   codestream_seek (pos + data16);
  1267. }
  1268.  
  1269. /* return pc of first real instruction */
  1270. /* from i386-dep.c */
  1271.  
  1272. i386_skip_prologue (pc)
  1273. {
  1274.   unsigned char op;
  1275.   int i;
  1276.   
  1277.   if (i386_get_frame_setup (pc) < 0)
  1278.     return (pc);
  1279.   
  1280.   /* found valid frame setup - codestream now points to 
  1281.    * start of push instructions for saving registers
  1282.    */
  1283.   
  1284.   /* skip over register saves */
  1285.   for (i = 0; i < 8; i++)
  1286.     {
  1287.       op = codestream_peek ();
  1288.       /* break if not pushl inst */
  1289.       if (op < 0x50 || op > 0x57) 
  1290.     break;
  1291.       codestream_get ();
  1292.     }
  1293.   
  1294.   i386_follow_jump ();
  1295.   
  1296.   return (codestream_tell ());
  1297. }
  1298.  
  1299.